package localFiles;

/***
 * 
 * @author Ragnvald Fuglestein
 *
 */

import java.io.File;
import last.fm.LastFmTrackAddon;
import library.Library;
import library.PlayList;
import baseStructure.Addon;
import baseStructure.Artist;
import baseStructure.ExtendedSearch;
import baseStructure.SearchArtist;
import baseStructure.SearchTrack;
import baseStructure.SortedList;
import baseStructure.Track;


//TODO: Make more generic
public class WriteLovedList {
	
	/***
	 * Create playlists with loved tracks in each artist folder
	 */
	public static void CreateLovedPlayListInArtistFolder() {
		SearchArtist sa = new SearchArtist();
		sa.addSearch(new ExtendedSearch(LocalArtistAddon.ADDON_NAME, "file"));
		
		SortedList<Artist> alist = new SortedList<>(600,20);
		
		Library.getInstance().getArtists(alist, sa);
		for (Artist artist : alist) {
			SearchTrack search = new SearchTrack();
			search.addSearch(new ExtendedSearch(LastFmTrackAddon.ADDON_NAME, "lovedby"));
			search.addSearch(new ExtendedSearch(LocalTrackAddon.ADDON_NAME, "file"));
			
			SortedList<Track> list = new SortedList<>();
			artist.getTracks(list, search);
			PlayList tracklist = new PlayList(artist.getName());
			for (Track track : list) {
				tracklist.append(track);
			}
			Addon addon = artist.getAddon(LocalArtistAddon.ADDON_NAME);
			File outfile = new File(((LocalArtistAddon)addon).getFile().get(0) + File.separator + "!Loved-" + artist + ".mp3");
			tracklist.writePlayListM3U(outfile);
		}
	}
}
